<template>
	<view>
		<view class="img_head">
			<view style="width: 180px;height: auto; background-color: rgba(96, 98, 102, 0.5);">
				<l-painter ref="painter">
					<l-painter-view  css=" border-radius: 8px; width: 180px; background: rgba(96, 98, 102, 0.5); padding: 30rpx; color: #FFFFFF">
						<text>
							测试测试
						</text>
					</l-painter-view>
				</l-painter>
			</view>
		</view>
		
		<button @click="onImg">生成图片</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
			onImg() {
				this.$refs.painter.canvasToTempFilePathSync({
					fileType: "jpg",
					// 如果返回的是base64是无法使用 saveImageToPhotosAlbum，需要设置 pathType为url
					pathType: 'url',
					quality: 1,
					success: (res) => {
						console.log(res.tempFilePath);
						// 非H5 保存到相册
						// H5 提示用户长按图另存
						uni.saveImageToPhotosAlbum({
							filePath: res.tempFilePath,
							success: function() {
								console.log('save success');
							}
						});
					},
				});
			}
		},
		onLoad() {
			
		}
	}
</script>

<style scoped>
.img_head{
	width: 100%;
	height: 400rpx;
	background-color: #303133;
	display: flex;
	align-items: center;
	justify-content: center;
	text-align: center;
}
</style>